package mlz.a_threadapi;

public class Demo04 {
    public static void main(String[] args) {
        Runnable r1 = new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    Thread t = Thread.currentThread();
                    System.out.println(t.getName() + ":" + i);
                }
            }
        };

        Runnable r2 = new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    Thread t = Thread.currentThread();
                    System.out.println(t.getName() + ":" + i);
                }
            }
        };



        Thread t1 = new Thread(r1);
        Thread t2 = new Thread(r2);

        //设置t1  和 t2的名字
        t1.setName("女神"); //正常在执行的线程
        t2.setName("备胎"); //守护线程

        t2.setDaemon(true);

        t1.start();
        t2.start();
    }
}
